﻿using Common.Utility;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Dapper
{
    public class ConnectionFactory
    {
        public static IDbConnection CreateConnection<T>(string conStr) where T : IDbConnection, new()
        {
            IDbConnection connection = new T();
            connection.ConnectionString = conStr;
            connection.Open();
            return connection;
        }

        public static IDbConnection CreateSqlConnection()
        {
            var sqlConnectionString = AppSetting.GetAppSetting("DbConnectionString");
            return CreateConnection<SqlConnection>(sqlConnectionString);
        }
    }
}
